package com.forlove.app.qselect.friend.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.forlove.app.R;
import com.forlove.app.common.widget.recyview.BaseRecyclerAdapter;
import com.forlove.app.common.widget.recyview.ViewHolder;
import com.forlove.app.qselect.friend.entity.MineFriendEntity;
import com.forlove.app.qselect.friend.entity.NewsFriendsStatus;
import com.forlove.app.qselect.friend.entity.SearchFriendEntity;
import com.forlove.app.qselect.friend.presenter.MineNewFriendPresenter;
import com.forlove.app.qselect.friend.ui.SearchUserInfoActivity;
import com.forlove.app.qselect.index.ui.MineInfoActivity;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 新的好友请求
 * Created by yjl on 2017/10/14.
 */

public class SchoolFriendAdapter extends BaseRecyclerAdapter<MineFriendEntity> {
    private MineNewFriendPresenter presenter;


    /**
     * 默认全显示
     *
     * @param context
     * @param itemView
     * @param mDatas
     * @param presenter
     */
    public SchoolFriendAdapter(Context context, int itemView, List<MineFriendEntity> mDatas,
                               MineNewFriendPresenter presenter) {
        super(context, itemView, mDatas);
        this.presenter = presenter;

    }


    @Override
    protected void convertView(ViewHolder holder, final MineFriendEntity entity, int position) {
        presenter.loadImageView(mContext, holder.getView(R.id.view_friend_photo),
                entity.img, R.mipmap.image_mine_friend_avatar);
        holder.setText(R.id.text_friend__name, entity.getAvaliableName());
        TextView text_friend_states = holder.getView(R.id.text_friend_states);
        if (entity.status == NewsFriendsStatus.UNINVITED.getCode()) {
            //可以邀请,或者已经邀请
            text_friend_states.setBackground(mContext.getResources().getDrawable(R.drawable.bt_invite_selector));
            text_friend_states.setTextColor(mContext.getResources().getColor(R.color.white));
            text_friend_states.setText(mContext.getString(R.string.str_invite_friend));
            text_friend_states.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //添加好友，好友申请页面
                    SearchFriendEntity searchFriendEntity = new SearchFriendEntity();
                    searchFriendEntity.friendEntity = entity;
                    searchFriendEntity.isFriend = false;
                    searchFriendEntity.note_times = entity.charm;
                    Intent intent = new Intent(mContext, SearchUserInfoActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putSerializable("friendinfo", searchFriendEntity);
                    bundle.putString("mobile", entity.getAvaliableMobile());
                    intent.putExtras(bundle);
                    mContext.startActivity(intent);
                }
            });
        } else if (entity.status == NewsFriendsStatus.UNADDED.getCode()) {
            //添加
            text_friend_states.setBackground(mContext.getResources().getDrawable(R.drawable.bt_invite_selector));
            text_friend_states.setTextColor(mContext.getResources().getColor(R.color.white));
            text_friend_states.setText(mContext.getString(R.string.str_add_friend));
            text_friend_states.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //添加好友，好友申请页面
                    SearchFriendEntity searchFriendEntity = new SearchFriendEntity();
                    searchFriendEntity.friendEntity = entity;
                    searchFriendEntity.isFriend = false;
                    searchFriendEntity.note_times = entity.charm;
                    Intent intent = new Intent(mContext, SearchUserInfoActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putSerializable("friendinfo", searchFriendEntity);
                    bundle.putString("mobile", entity.getAvaliableMobile());
                    intent.putExtras(bundle);
                    mContext.startActivity(intent);
                }
            });
        } else if (entity.status == NewsFriendsStatus.WAITING.getCode()) {
            //等待验证
            text_friend_states.setBackgroundColor(mContext.getResources().getColor(R.color.white));
            text_friend_states.setTextColor(mContext.getResources().getColor(R.color.str_color_gray));
            text_friend_states.setText(mContext.getString(R.string.str_waiting_confirm));
            text_friend_states.setOnClickListener(null);
        } else if (entity.status == NewsFriendsStatus.CONFIRMED.getCode()) {
            //已经添加
            text_friend_states.setBackgroundColor(mContext.getResources().getColor(R.color.white));
            text_friend_states.setTextColor(mContext.getResources().getColor(R.color.str_color_gray));
            text_friend_states.setText(mContext.getString(R.string.str_added_friend));
            text_friend_states.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(mContext, MineInfoActivity.class);
                    Bundle bundle = new Bundle();
                    bundle.putString("mobile", entity.mobile);
                    intent.putExtras(bundle);
                    mContext.startActivity(intent);
                }
            });
        } else if (entity.status == NewsFriendsStatus.UNCONFIRM.getCode()) {
            //同意
            text_friend_states.setBackground(mContext.getResources().getDrawable(R.drawable.bt_agree_add_selector));
            text_friend_states.setTextColor(mContext.getResources().getColor(R.color.common_green));
            text_friend_states.setText(mContext.getString(R.string.str_agree_add));
            text_friend_states.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Map param = new HashMap();
                    param.put("friend", entity.mobile);
                    presenter.loadAgreeFriendData(param);
                }
            });
        } else if (entity.status == NewsFriendsStatus.INVITED.getCode()) {
            text_friend_states.setBackgroundColor(mContext.getResources().getColor(R.color.white));
            text_friend_states.setTextColor(mContext.getResources().getColor(R.color.str_color_gray));
            text_friend_states.setText(mContext.getString(R.string.str_has_invited));
            text_friend_states.setOnClickListener(null);
        }

    }

}
